#!/usr/bin/python
#
# name....: index.py
# author..: Herb Lainchbury
# company.: Dynamic Solutions Inc.
# purpose.: Runs datazoomer launcher
#

try:
    import sys, os, ConfigParser

    # Configuration information for this site
    site_configuration_file = '../dz.ini'

    # Get library location from config file
    cp = ConfigParser.ConfigParser()
    cp.read(site_configuration_file)
    try:
        framework_library_path = cp.get('lib','path')
    except:
        framework_library_path = '../lib'

    # Apppend the framework path to the sys.path
    absolute_system_lib_path = os.path.abspath(framework_library_path)
    if not absolute_system_lib_path in sys.path:
        sys.path.append(absolute_system_lib_path)

    import launch
    launch.run_as_cgi(__file__,os.path.abspath(site_configuration_file))

except:
    import traceback

    try:
        error = cp.get('error','mode')
    except:
        error = '2'

    # Write an error to the browser and to the traceback
    t = traceback.format_exc()
    print 'Content-type: text/html\n\n'
    print 'Error launching DataZoomer.  Please refer to the install docs.<br>\n'
    if error == '2':
        print '<pre>%s</pre>' % t 
    f = open('traceback','w')
    f.write(t)
    f.close()

